/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.service.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.comac.ins.common.core.domain.model.LoginUser;
import com.comac.ins.common.core.exception.base.BaseException;
import com.comac.ins.common.core.utils.MapstructUtils;
import com.comac.ins.common.core.utils.StringUtils;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.satoken.utils.LoginHelper;
import com.comac.ins.isfd.constant.enums.IsfdDatasourceTaskStatusEnum;
import com.comac.ins.isfd.domain.IsfdDatasourceDataIntegrationTask;
import com.comac.ins.isfd.domain.IsfdDatasourceTaskDataSourceConfig;
import com.comac.ins.isfd.domain.bo.IsfdDatasourceDataIntegrationTaskBo;
import com.comac.ins.isfd.domain.bo.IsfdDatasourceTaskDataSourceConfigBo;
import com.comac.ins.isfd.domain.bo.IsfdDatasourceTaskSchedulingConfigBo;
import com.comac.ins.isfd.domain.bo.IsfdDatasourceTaskTargetConfigBo;
import com.comac.ins.isfd.domain.vo.IsfdDatasourceDataIntegrationTaskVo;
import com.comac.ins.isfd.domain.vo.IsfdDatasourceTableVo;
import com.comac.ins.isfd.domain.vo.IsfdDatasourceTaskDataSourceConfigVo;
import com.comac.ins.isfd.domain.vo.IsfdDatasourceTaskSchedulingConfigVo;
import com.comac.ins.isfd.domain.vo.IsfdDatasourceTaskTargetConfigVo;
import com.comac.ins.isfd.mapper.IsfdDatasourceDataIntegrationTaskMapper;
import com.comac.ins.isfd.mapper.IsfdDatasourceTaskDataSourceConfigMapper;
import com.comac.ins.isfd.mapper.IsfdDatasourceTaskTargetConfigMapper;
import com.comac.ins.isfd.service.IIsfdDatasourceDataIntegrationTaskService;
import com.comac.ins.system.domain.SysUser;
import com.comac.ins.system.domain.vo.SysUserVo;
import com.comac.ins.system.mapper.SysUserMapper;
import lombok.RequiredArgsConstructor;

/**
 * 数据源数据集成任务Service业务层处理
 *
 * @author Lion Li
 * @date 2024-10-11
 */
@RequiredArgsConstructor
@Service
public class IsfdDatasourceDataIntegrationTaskServiceImpl implements IIsfdDatasourceDataIntegrationTaskService {
    private IsfdDatasourceDataIntegrationTaskMapper baseMapper;

    private IsfdDatasourceTaskDataSourceConfigMapper isfdDatasourceTaskDataSourceConfigMapper;

    private IsfdDatasourceTaskTargetConfigMapper isfdDatasourceTaskTargetConfigMapper;

    private IsfdDatasourceTaskTargetConfigServiceImpl isfdDatasourceTaskTargetConfigServiceImpl;

    private IsfdDatasourceTaskSchedulingConfigServiceImpl isfdDatasourceTaskSchedulingConfigServiceImpl;

    private SysUserMapper userMapper;

    @Autowired
    public void setBaseMapper(IsfdDatasourceDataIntegrationTaskMapper baseMapper) {
        this.baseMapper = baseMapper;
    }

    @Autowired
    public void setIsfdDatasourceTaskDataSourceConfigMapper(IsfdDatasourceTaskDataSourceConfigMapper isfdDatasourceTaskDataSourceConfigMapper) {
        this.isfdDatasourceTaskDataSourceConfigMapper = isfdDatasourceTaskDataSourceConfigMapper;
    }

    @Autowired
    public void setIsfdDatasourceTaskTargetConfigMapper(IsfdDatasourceTaskTargetConfigMapper isfdDatasourceTaskTargetConfigMapper) {
        this.isfdDatasourceTaskTargetConfigMapper = isfdDatasourceTaskTargetConfigMapper;
    }

    @Autowired
    public void setIsfdDatasourceTaskTargetConfigServiceImpl(IsfdDatasourceTaskTargetConfigServiceImpl isfdDatasourceTaskTargetConfigServiceImpl) {
        this.isfdDatasourceTaskTargetConfigServiceImpl = isfdDatasourceTaskTargetConfigServiceImpl;
    }

    @Autowired
    public void setIsfdDatasourceTaskSchedulingConfigServiceImpl(IsfdDatasourceTaskSchedulingConfigServiceImpl isfdDatasourceTaskSchedulingConfigServiceImpl) {
        this.isfdDatasourceTaskSchedulingConfigServiceImpl = isfdDatasourceTaskSchedulingConfigServiceImpl;
    }

    @Autowired
    public void setUserMapper(SysUserMapper userMapper) {
        this.userMapper = userMapper;
    }

    /**
     * 查询数据源数据集成任务
     *
     * @param id 主键
     * @return 数据源数据集成任务
     */
    @Override
    public IsfdDatasourceDataIntegrationTaskVo queryById(Long id) {
        LambdaQueryWrapper<IsfdDatasourceDataIntegrationTask> lqw = new LambdaQueryWrapper<>();
        lqw.eq(IsfdDatasourceDataIntegrationTask::getIsDeleted, 0);
        lqw.eq(IsfdDatasourceDataIntegrationTask::getId, id);
        IsfdDatasourceDataIntegrationTaskVo result = baseMapper.selectVoOne(lqw);

        if (Objects.nonNull(result)) {
            if (Objects.nonNull(result.getCreateBy())) {
                SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserId, result.getCreateBy()));
                result.setCreateByName(sysUser.getUserName());
            }
            if (Objects.nonNull(result.getStatus())) {
                String descByValue = IsfdDatasourceTaskStatusEnum.getDescByValue(result.getStatus());
                result.setStatusByName(descByValue);
            }

            //查询源配置
            LambdaQueryWrapper<IsfdDatasourceTaskDataSourceConfig> lqwc = new LambdaQueryWrapper<>();
            lqwc.eq(IsfdDatasourceTaskDataSourceConfig::getIsDeleted, 0);
            lqwc.eq(IsfdDatasourceTaskDataSourceConfig::getTaskId, result.getId());
            IsfdDatasourceTaskDataSourceConfigVo isfdDatasourceTaskDataSourceConfigVo = isfdDatasourceTaskDataSourceConfigMapper.selectVoOne(lqwc);
            result.setDatasourceTaskDataSourceConfigVo(isfdDatasourceTaskDataSourceConfigVo);
            //查询目标配置
            IsfdDatasourceTaskTargetConfigBo isfdDatasourceTaskTargetConfigBo = new IsfdDatasourceTaskTargetConfigBo();
            isfdDatasourceTaskTargetConfigBo.setTaskId(result.getId());
            isfdDatasourceTaskTargetConfigBo.setIsDeleted(0);
            List<IsfdDatasourceTaskTargetConfigVo> isfdDatasourceTaskTargetConfigVoList = isfdDatasourceTaskTargetConfigServiceImpl.queryList(isfdDatasourceTaskTargetConfigBo);
            if (CollectionUtils.isNotEmpty(isfdDatasourceTaskTargetConfigVoList)) {
                result.setDatasourceTaskTargetConfigVo(isfdDatasourceTaskTargetConfigVoList.get(0));
            }
            //查询调度配置
            IsfdDatasourceTaskSchedulingConfigBo isfdDatasourceTaskSchedulingConfigBo = new IsfdDatasourceTaskSchedulingConfigBo();
            isfdDatasourceTaskSchedulingConfigBo.setTaskId(result.getId());
            isfdDatasourceTaskSchedulingConfigBo.setIsDeleted(0);
            List<IsfdDatasourceTaskSchedulingConfigVo> isfdDatasourceTaskSchedulingConfigList = isfdDatasourceTaskSchedulingConfigServiceImpl.queryList(isfdDatasourceTaskSchedulingConfigBo);
            if (CollectionUtils.isNotEmpty(isfdDatasourceTaskSchedulingConfigList)) {
                result.setDatasourceTaskSchedulingConfigVo(isfdDatasourceTaskSchedulingConfigList.get(0));
            }
        }
        return result;
    }

    /**
     * 分页查询数据源数据集成任务列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 数据源数据集成任务分页列表
     */
    @Override
    public TableDataInfo<IsfdDatasourceDataIntegrationTaskVo> queryPageList(IsfdDatasourceDataIntegrationTaskBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<IsfdDatasourceDataIntegrationTask> lqw = buildQueryWrapper(bo);
        pageQuery.setOrderByColumn("create_time");
        lqw.eq(IsfdDatasourceDataIntegrationTask::getIsDeleted, 0);
        // 时间区间查询
        Map<String, Object> params = bo.getParams();
        String beginTime = (String) params.get("beginTime");
        String endTime = (String) params.get("endTime");
        if (beginTime != null && !beginTime.isEmpty()) {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date beginDate;
            try {
                beginDate = df.parse(beginTime);
            } catch (ParseException e) {
                throw new RuntimeException("开始日期转换失败");
            }
            lqw.ge(IsfdDatasourceDataIntegrationTask::getCreateTime, beginDate);
        }
        if (endTime != null && !endTime.isEmpty()) {
            // endTime = '2024-06-30' 意味着 包含2024年6月30日
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date endDate;
            try {
                endDate = df.parse(endTime);
            } catch (ParseException e) {
                throw new RuntimeException("结束日期转换失败");
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(endDate);
            calendar.add(Calendar.DATE, 1);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            lqw.lt(IsfdDatasourceDataIntegrationTask::getCreateTime, calendar.getTime());
        }

        Page<IsfdDatasourceDataIntegrationTaskVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);

        List<IsfdDatasourceDataIntegrationTaskVo> records = result.getRecords();
        for (IsfdDatasourceDataIntegrationTaskVo datasourceDataIntegrationTaskVo : records) {
            if (Objects.nonNull(datasourceDataIntegrationTaskVo.getCreateBy())) {
                SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserId, datasourceDataIntegrationTaskVo.getCreateBy()));
                datasourceDataIntegrationTaskVo.setCreateByName(sysUser.getUserName());
            }
            if (Objects.nonNull(datasourceDataIntegrationTaskVo.getStatus())) {
                String descByValue = IsfdDatasourceTaskStatusEnum.getDescByValue(datasourceDataIntegrationTaskVo.getStatus());
                datasourceDataIntegrationTaskVo.setStatusByName(descByValue);
            }

        }

        return TableDataInfo.build(result);
    }

    /**
     * 查询符合条件的数据源数据集成任务列表
     *
     * @param bo 查询条件
     * @return 数据源数据集成任务列表
     */
    @Override
    public List<IsfdDatasourceDataIntegrationTaskVo> queryList(IsfdDatasourceDataIntegrationTaskBo bo) {
        LambdaQueryWrapper<IsfdDatasourceDataIntegrationTask> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<IsfdDatasourceDataIntegrationTask> buildQueryWrapper(IsfdDatasourceDataIntegrationTaskBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<IsfdDatasourceDataIntegrationTask> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(bo.getTaskName()), IsfdDatasourceDataIntegrationTask::getTaskName, bo.getTaskName());
        lqw.eq(StringUtils.isNotBlank(bo.getSyncType()), IsfdDatasourceDataIntegrationTask::getSyncType, bo.getSyncType());
        lqw.eq(StringUtils.isNotBlank(bo.getTaskType()), IsfdDatasourceDataIntegrationTask::getTaskType, bo.getTaskType());
        lqw.eq(StringUtils.isNotBlank(bo.getTaskDescription()), IsfdDatasourceDataIntegrationTask::getTaskDescription, bo.getTaskDescription());
        lqw.eq(bo.getIsDeleted() != null, IsfdDatasourceDataIntegrationTask::getIsDeleted, bo.getIsDeleted());
        lqw.eq(bo.getStatus() != null, IsfdDatasourceDataIntegrationTask::getStatus, bo.getStatus());
        return lqw;
    }

    /**
     * 新增数据源数据集成任务
     *
     * @param bo 数据源数据集成任务
     * @return 是否新增成功
     */
    @Override
    public Boolean insertByBo(IsfdDatasourceDataIntegrationTaskBo bo) {
        LoginUser loginUser = LoginHelper.getLoginUser();
        bo.setCreateBy(loginUser.getUserId());
        bo.setUpdateBy(loginUser.getUserId());
        bo.setCreateDept(loginUser.getDeptId());
        bo.setIsDeleted(0);
        bo.setStatus(IsfdDatasourceTaskStatusEnum.DEFAULT.getValue());
        IsfdDatasourceDataIntegrationTask add = MapstructUtils.convert(bo, IsfdDatasourceDataIntegrationTask.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;

        if (flag) {
            //保存源配置
            IsfdDatasourceTaskDataSourceConfigBo isfdDatasourceTaskDataSourceConfigBo = bo.getDatasourceTaskDataSourceConfigBo();
            IsfdDatasourceTaskDataSourceConfig isfdDatasourceTaskDataSourceConfig = new IsfdDatasourceTaskDataSourceConfig();
            BeanUtils.copyProperties(isfdDatasourceTaskDataSourceConfigBo, isfdDatasourceTaskDataSourceConfig);
            isfdDatasourceTaskDataSourceConfig.setTaskId(add.getId());
            isfdDatasourceTaskDataSourceConfig.setIsDeleted(0);
            isfdDatasourceTaskDataSourceConfigMapper.insert(isfdDatasourceTaskDataSourceConfig);
            //保存目标配置
            IsfdDatasourceTaskTargetConfigBo isfdDatasourceTaskTargetConfigBo = bo.getDatasourceTaskTargetConfigBo();
            if (Objects.nonNull(isfdDatasourceTaskTargetConfigBo)) {
                isfdDatasourceTaskTargetConfigBo.setTaskId(add.getId());
                isfdDatasourceTaskTargetConfigBo.setIsDeleted(0);
                isfdDatasourceTaskTargetConfigServiceImpl.save(isfdDatasourceTaskTargetConfigBo);
            }
            //保存调度配置
            IsfdDatasourceTaskSchedulingConfigBo isfdDatasourceTaskSchedulingConfigBo = bo.getDatasourceTaskSchedulingConfigBo();
            if (Objects.nonNull(isfdDatasourceTaskSchedulingConfigBo)) {
                isfdDatasourceTaskSchedulingConfigBo.setTaskId(add.getId());
                isfdDatasourceTaskSchedulingConfigBo.setIsDeleted(0);
                isfdDatasourceTaskSchedulingConfigServiceImpl.save(isfdDatasourceTaskSchedulingConfigBo);
            }
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改数据源数据集成任务
     *
     * @param bo 数据源数据集成任务
     * @return 是否修改成功
     */
    @Override
    public Boolean updateByBo(IsfdDatasourceDataIntegrationTaskBo bo) {
        IsfdDatasourceDataIntegrationTask update = MapstructUtils.convert(bo, IsfdDatasourceDataIntegrationTask.class);
        validEntityBeforeSave(update);

        LoginUser loginUser = LoginHelper.getLoginUser();
        bo.setUpdateBy(loginUser.getUserId());

        // 更新基本信息
        boolean flag = baseMapper.updateById(update) > 0;

        if (flag) {
            //修改保存源配置
            deleteDatasourceTaskDataSourceConfig(bo.getId());
            IsfdDatasourceTaskDataSourceConfigBo isfdDatasourceTaskDataSourceConfigBo = bo.getDatasourceTaskDataSourceConfigBo();
            isfdDatasourceTaskDataSourceConfigBo.setId(null);
            isfdDatasourceTaskDataSourceConfigBo.setTaskId(bo.getId());
            isfdDatasourceTaskDataSourceConfigBo.setIsDeleted(0);
            IsfdDatasourceTaskDataSourceConfig addDatasourceTaskDataSourceConfig = MapstructUtils.convert(isfdDatasourceTaskDataSourceConfigBo, IsfdDatasourceTaskDataSourceConfig.class);
            isfdDatasourceTaskDataSourceConfigMapper.insert(addDatasourceTaskDataSourceConfig);
            //修改保存目标配置
            IsfdDatasourceTaskTargetConfigBo isfdDatasourceTaskTargetConfigBo = bo.getDatasourceTaskTargetConfigBo();
            if (Objects.nonNull(isfdDatasourceTaskTargetConfigBo)) {
                isfdDatasourceTaskTargetConfigBo.setTaskId(bo.getId());
                isfdDatasourceTaskTargetConfigBo.setIsDeleted(0);
                isfdDatasourceTaskTargetConfigServiceImpl.save(isfdDatasourceTaskTargetConfigBo);
            }
            //修改保存调度配置
            IsfdDatasourceTaskSchedulingConfigBo isfdDatasourceTaskSchedulingConfigBo = bo.getDatasourceTaskSchedulingConfigBo();
            if (Objects.nonNull(isfdDatasourceTaskSchedulingConfigBo)) {
                isfdDatasourceTaskSchedulingConfigBo.setTaskId(bo.getId());
                isfdDatasourceTaskSchedulingConfigBo.setIsDeleted(0);
                isfdDatasourceTaskSchedulingConfigServiceImpl.save(isfdDatasourceTaskSchedulingConfigBo);
            }
        }
        return flag;
    }

    private void deleteDatasourceTaskDataSourceConfig(Long taskId) {
        LambdaQueryWrapper<IsfdDatasourceTaskDataSourceConfig> lqw = new LambdaQueryWrapper<>();
        lqw.eq(IsfdDatasourceTaskDataSourceConfig::getTaskId, taskId);

        IsfdDatasourceTaskDataSourceConfig updateEntity = new IsfdDatasourceTaskDataSourceConfig();
        updateEntity.setIsDeleted(1);
        isfdDatasourceTaskDataSourceConfigMapper.update(updateEntity, lqw);
    }

    @Override
    public Boolean updateStatusAndTriggerTime(Integer status, Long taskId, Date triggerTime) {
        LambdaQueryWrapper<IsfdDatasourceDataIntegrationTask> lqw = new LambdaQueryWrapper<>();
        lqw.eq(IsfdDatasourceDataIntegrationTask::getId, taskId);

        IsfdDatasourceDataIntegrationTask task = new IsfdDatasourceDataIntegrationTask();
        task.setStatus(status);
        if (triggerTime != null) {
            task.setTriggerTime(triggerTime);
        }

        if (baseMapper.update(task, lqw) > 0) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;

    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(IsfdDatasourceDataIntegrationTask entity) {
        //TODO 做一些数据校验,如唯一约束
        IsfdDatasourceDataIntegrationTaskBo isfdDatasourceDataIntegrationTaskBo = new IsfdDatasourceDataIntegrationTaskBo();
        isfdDatasourceDataIntegrationTaskBo.setTaskName(entity.getTaskName());

        List<IsfdDatasourceDataIntegrationTaskVo> isfdDatasourceDataIntegrationTaskVoList = queryList(isfdDatasourceDataIntegrationTaskBo);
        for (IsfdDatasourceDataIntegrationTaskVo isfdDatasourceDataIntegrationTaskVo : isfdDatasourceDataIntegrationTaskVoList) {
            if (Objects.nonNull(entity.getId())) {
                if (!entity.getId().equals(isfdDatasourceDataIntegrationTaskVo.getId())) {
                    throw new RuntimeException("任务名称不能重复");
                }
            } else {
                throw new RuntimeException("任务名称不能重复");
            }
        }
    }

    /**
     * 校验并批量删除数据源数据集成任务信息
     *
     * @param id      待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    @Override
    public Boolean deleteWithValidById(Long id, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }

        LambdaQueryWrapper<IsfdDatasourceDataIntegrationTask> lqw = new LambdaQueryWrapper<>();
        lqw.eq(IsfdDatasourceDataIntegrationTask::getId, id);

        IsfdDatasourceDataIntegrationTask updateEntity = new IsfdDatasourceDataIntegrationTask();
        if (Objects.isNull(updateEntity)) {
            throw new BaseException("id为：" + id + "的任务不能删除，该任务不存在");
        }
        updateEntity.setIsDeleted(1);

        // 执行逻辑删除
        boolean flag = baseMapper.update(updateEntity, lqw) > 0;
        return flag;
    }

    @Override
    public List<IsfdDatasourceTableVo> getTablesByDataSource(IsfdDatasourceTaskDataSourceConfigBo bo) {
        List<IsfdDatasourceTableVo> tableList = new ArrayList<>();

        String url = bo.getUrl();
        String user = bo.getUserName();
        String password = bo.getSecretCode();
        String databaseName = bo.getDatabaseName();
        String tableName = bo.getTableName();
        String connectionUrl;
        if (StringUtils.isNotEmpty(url)) {
            if (!url.startsWith("jdbc:mysql://")) {
                url = "jdbc:mysql://" + url;
            }
            connectionUrl = url;
        } else {
            throw new RuntimeException("数据源URL不能为空");
        }

        try (Connection connection = DriverManager.getConnection(connectionUrl, user, password);
             Statement statement = connection.createStatement()) {

            if (StringUtils.isEmpty(databaseName)) {
                String query = "SHOW DATABASES";
                try (ResultSet resultSet = statement.executeQuery(query)) {

                    while (resultSet.next()) {
                        String dbName = resultSet.getString(1);
                        IsfdDatasourceTableVo tableVo = new IsfdDatasourceTableVo();
                        tableVo.setDatabaseName(dbName);
                        tableList.add(tableVo);
                    }
                }
            } else {

                if (StringUtils.isEmpty(tableName)) {
                    // 查询所有表名
                    String query = "SHOW TABLES FROM `" + databaseName + "`";
                    try (ResultSet resultSet = statement.executeQuery(query)) {

                        while (resultSet.next()) {
                            String tableNameSearch = resultSet.getString(1);
                            IsfdDatasourceTableVo tableVo = new IsfdDatasourceTableVo();
                            tableVo.setTableName(tableNameSearch);
                            tableList.add(tableVo);
                        }
                    }
                } else {
                    // 查询指定数据库的指定表的字段名
                    String query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" + databaseName + "'";
                    query += " AND TABLE_NAME = '" + bo.getTableName() + "'";

                    try (ResultSet resultSet = statement.executeQuery(query)) {

                        while (resultSet.next()) {
                            String fieldName = resultSet.getString("COLUMN_NAME");
                            IsfdDatasourceTableVo tableVo = new IsfdDatasourceTableVo();
                            tableVo.setFieldName(fieldName);
                            tableList.add(tableVo);
                        }
                    }
                }
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return tableList;
    }
}
